//
//  MYTableViewCell.m
//  QuickCure
//
//  Created by 小灰灰 on 16/9/14.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "MYTableViewCell.h"
#import "BFZDataModel.h"
#import "BFZTableViewController.h"
@interface MYTableViewCell()
@property(nonatomic,strong)UIButton *selectedBtn;
@property(nonatomic,strong)NSMutableArray *btnArr;
@end

@implementation MYTableViewCell
-(NSMutableArray *)muArr
{
    if(!_muArr)
    {
        _muArr =[NSMutableArray array];
    }
    return _muArr;
}
-(NSMutableArray *)btnArr
{
    if(!_btnArr)
    {
        _btnArr =[NSMutableArray array];
    }
    return _btnArr;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self creatUI];
    }
    return self;
}
-(void)creatUI
{
    UIButton *btn =[[UIButton alloc] init];
    self.btn = btn;
    [btn setTitle:@"订阅" forState:UIControlStateNormal];
    
    //点击btn
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"已订阅" forState:UIControlStateSelected];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    [btn setBackgroundColor:kThemeColor];
    //设置圆角
    btn.layer.cornerRadius = 3;
    btn.clipsToBounds = YES;
    
    [btn setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateNormal];
    [self.contentView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView).offset(-20);
        make.width.mas_equalTo(@80);
        make.height.mas_equalTo(@30);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    UILabel *label =[[UILabel alloc] init];
    self.label = label;
    [label setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(self.contentView).offset(20);
        make.right.mas_equalTo(btn.mas_left);
    }];
    
    
}
-(void)setModel:(BFZDataModel *)model
{
    _model = model;
    self.label.text = self.model.complication_name;
    
    
}
-(void)click:(UIButton *)btn
{
    btn.selected = !btn.selected;
    if(btn.selected)
    {
        [self.muArr addObject:self.model.complication_name];

    }else
    {
          [self.muArr removeObject:self.model.complication_name];
     }
    
    if(self.strBlock)
    {
        self.strBlock(self.muArr.copy);
    }

}


   

@end
